import 'package:dio/dio.dart';
import 'package:private_journey/DataSets.dart';

main() async {
  var qrInfo = await MusicService.createLoginQrCode('');
  print(qrInfo);
}

class QrInfo {
  String qrCode;
  String qrUrl;

  QrInfo({required this.qrCode, required this.qrUrl});

  @override
  String toString() {
    return 'QrInfo{qrCode: $qrCode, qrUrl: $qrUrl}';
  }
}

class MusicService {
  static Future<bool> checkKey(String key) async {
    Dio dio = Dio(
      BaseOptions(
        headers: {
          'User-Agent':
              'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0',
        },
      ),
    );
    var timestamp = DateTime.now().millisecondsSinceEpoch;
    var keyRes = await dio.get(
      'http://117.72.107.9:3000/login/qr/check?key=$key&timestamp=$timestamp',
    );
    
    return false;
  }

  static Future<String> createQrKey() async {
    Dio dio = Dio(
      BaseOptions(
        headers: {
          'User-Agent':
              'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0',
        },
      ),
    );
    var timestamp = DateTime.now().millisecondsSinceEpoch;
    var keyRes = await dio.get(
      'http://117.72.107.9:3000/login/qr/key?timestamp=$timestamp',
    );
    var key = keyRes.data['data']['unikey'];
    return key;
  }

  static Future<QrInfo> createLoginQrCode(String key) async {
    Dio dio = Dio(
      BaseOptions(
        headers: {
          'User-Agent':
              'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0',
        },
      ),
    );
    var timestamp = DateTime.now().millisecondsSinceEpoch;
    //获取当前的时间戳
    var qrRes = await dio.get(
      'http://117.72.107.9:3000/login/qr/create?key=$key&qrimg=true&timestamp=$timestamp',
    );
    var qrCode = qrRes.data['data']['qrimg'];
    var qrUrl = qrRes.data['data']['qrurl'];
    return QrInfo(qrCode: qrCode, qrUrl: qrUrl);
  }
}
